# https://hub.docker.com/_/ubuntu/tags

# FROM ubuntu:noble-20241118
# amd64, arm32v7, arm64v8, ppc64le, riscv64, s390x
# ubuntu 24.04
FROM amd64/ubuntu:noble-20241118.1
# FROM arm32v7/ubuntu:noble-20241118.1
# FROM arm64v8/ubuntu:noble-20241118.1
# FROM riscv64/ubuntu:noble-20241118.1

SHELL ["/bin/bash", "-c"]

# update sources
# https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
RUN echo "" > /etc/apt/sources.list \
	&& echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释" >> /etc/apt/sources.list \
	&& echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "" >> /etc/apt/sources.list \
	&& echo "# 以下安全更新软件源包含了官方源与镜像站配置，如有需要可自行修改注释切换" >> /etc/apt/sources.list \
	&& echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "" >> /etc/apt/sources.list \
	&& echo "# 预发布软件源，不建议启用" >> /etc/apt/sources.list \
	&& echo "# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
	&& echo "" >> /etc/apt/sources.list

# to change apt source, ca-certificate must be installed
# update and install other packages
# apt-get -o Acquire::https::Verify-Peer="false"
RUN sed -i 's%^%# %g' /etc/apt/sources.list.d/* || true \
	&& echo "Acquire { https::Verify-Peer false }" > /etc/apt/apt.conf.d/99verify-peer.conf \
	&& sed -i 's%^%# %g' /etc/apt/sources.list.d/* || true \
	&& apt-get update \
	&& apt-get install -y ca-certificates \
	&& rm -f /etc/apt/apt.conf.d/99verify-peer.conf \
	&& apt-get update \
	&& apt-get install --reinstall -y apt-utils ca-certificates \
	&& apt-get install -y sudo tzdata \
	&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
	&& dpkg-reconfigure -f noninteractive tzdata

# remove default user
# RUN userdel -f -r ubuntu || true

# docker treat path of Dockerfile as / if use . or ..
ADD envsetup.tar.gz /tmp/envsetup/
COPY *.sh /tmp/envsetup/
RUN bash /tmp/envsetup/_install.sh && \rm -fr /tmp/envsetup \
	&& apt-get autoremove \
	&& apt-get autoclean \
	&& apt-get clean \
	&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# configure
ARG user=dockeruser
ARG home_dir=/home/${user}

# create anonymous volume
# VOLUME ["${home_dir}"]

# C.UTF-8: support chinese
# ENV PS1 not take effect
ENV LANG=C.UTF-8 LANGUAGE=en_US:en \
	HOME=${home_dir} HISTTIMEFORMAT="[%F %T] "

# default user in docker
USER ${user}:${user}
WORKDIR ${home_dir}

CMD ["/bin/bash"]
